//判断本地是否记住过用户名
var uesrname = tool.getCookie('remember')
if (uesrname) {
    $('#remember').val(uesrname);
}
$('.submit').click(function () {
    //验证表单数据

    //禁用提交按钮 
    $(this).prop('disabled', true);
    //加载
    var loadindex = layer.load(1, {
        shade: [0.7, '#fff']
    });
    //发送ajax请求
    $.post('../php/login.php', $('form').serialize(), res => {
        //解构传过来的值
        var {
            meta: {
                status,
                msg
            }
        } = res;
        layer.close(loadindex);
        if (status === 1) {
            //存储登录成功的cookie
            tool.setCookie('username', $('[name="username"]').val(), 7200);
            //判断是否记住用户名
            if ($('#remember').prop('checked')) {
                tool.setCookie('remember', $('[name="username"]').val(), 7 * 24 * 3600)
            }
            layer.msg(msg, {
                icon: 6,
                time: 1500
            }, function () {
                var url = localStorage.getItem('url');
                if (url) {
                    localStorage.removeItem('url')
                    location.href = url;
                    return false;
                }
                location.href = '../index.html'

            })
        } else {
            $(this).prop('disabled', false);
            layer.msg(msg, {
                icon: 2,
                time: 1500
            })
        }
    }, 'json')
})